package com.duobaoyu.dby.supply.common.biz.bo.refund;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.duobaoyu.dby.channel.adapter.enums.biz.refund.AfterSaleStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.DiffBuilder;
import org.apache.commons.lang3.builder.DiffResult;
import org.apache.commons.lang3.builder.Diffable;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * @author yw
 * @description
 * @date 2023/9/27 16:39
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AfterSaleOutBO implements Serializable, Diffable<AfterSaleOutBO> {

    /**
     * 主键ID
     */
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 描述：渠道编码
     */
    private String channelCode;
    /**
     * 描述：订单编码
     */
    private String orderSn;

    /**
     * 业务来源
     */
    private String showServerName;
    /**
     * 描述：售后状态
     */
    private Integer status;

    /**
     * 退款状态
     */
    private Integer refundStatus;
    /**
     * 描述：售后渠道交易单号
     */
    private String afterSaleTradeOrderSn;
    /**
     * 描述：是否删除 0-否 1-是
     */
    private Integer delFlag;
    /**
     * 描述：售后单号
     */
    private String afterSaleSn;
    /**
     * 描述：客户寄回地址
     */
    private CustomerReturnAddressBO customerReturnAddress;

    /**
     * 描述：渠道父编号
     */
    private String channelOrderParentSn;
    /**
     * 描述：申请退款金额
     */
    private BigDecimal applyRefundAmount;
    /**
     * 描述：渠道售后单号
     */
    private String channelAfterSaleSn;
    /**
     * 描述：版本号-用作乐观锁
     */
    private Integer version;
    /**
     * 描述：售后来源 0 用户申请 1 运营申请 2 系统自动生成
     */
    private Integer afterSaleSource;
    /**
     * 描述：运费申请退款金额
     */
    private BigDecimal freightApplyRefundAmount;
    /**
     * 描述：渠道运费退款金额
     */
    private BigDecimal channelFreightActualRefundAmount;
    /**
     * 描述：失败原因
     */
    private String failReason;
	/**
	 * 取消原因
	 */
	private String cancelReason;

    /**
     * 调用来源
     */
    private String serverName;
    /**
     * 描述：订单渠道交易单号-和订单统一
     */
    private String channelTradeOrderSn;
    /**
     * 描述：售后类型
     */
    private Integer afterSaleType;
    /**
     * 描述：实际退款金额
     */
    private BigDecimal channelActualRefundAmount;

    /**
     * 描述：是否有发票
     */
    private Boolean hasInvoice;
    /**
     * 描述：业务售后单号
     */
    private String bizAfterSaleSn;

    /**
     * 描述：渠道订单编号
     */
    private String channelOrderSn;

    /**
     * 供应链三方交易单号
     */
    private String orderTradeSn;
    /**
     * 售后商品
     */
    private List<AfterSaleItemOutBO> items;

    /**
     * 联系人
     */
    private AfterSaleContactInfoBO contactInfo;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    private String mchId;


    private String userId;

	@Override
	public DiffResult<AfterSaleOutBO> diff(AfterSaleOutBO obj) {
		DiffBuilder<AfterSaleOutBO> diffBuilder =
				new DiffBuilder<>(this, obj, ToStringStyle.SHORT_PREFIX_STYLE);
		diffBuilder.append("售后状态", AfterSaleStatusEnum.getAfterSaleStatusDescribe(this.status),
				AfterSaleStatusEnum.getAfterSaleStatusDescribe(obj.getStatus()));
		diffBuilder.append("失败原因", this.failReason, obj.getFailReason());
		diffBuilder.append("取消原因", this.cancelReason, obj.getCancelReason());
		diffBuilder.append("客户寄回地址", this.customerReturnAddress, obj.getCustomerReturnAddress());
		if (Objects.nonNull(obj.getChannelActualRefundAmount())) {
			diffBuilder.append("实际退款金额", this.channelActualRefundAmount, obj.getChannelActualRefundAmount().setScale(2, RoundingMode.HALF_UP));
		}
		if (Objects.nonNull(obj.getFreightApplyRefundAmount())) {
			diffBuilder.append("运费申请退款金额", this.freightApplyRefundAmount, obj.getFreightApplyRefundAmount().setScale(2, RoundingMode.HALF_UP));
		}
		return diffBuilder.build();
	}

	public static void main(String[] args) {
		BigDecimal bigDecimal = BigDecimal.valueOf(100);
		System.out.println(bigDecimal.setScale(2, RoundingMode.HALF_UP));
	}
}
